<?php
/**
 * DolphinGTK - phpGtk framework
 *
 * Графический модуль
 *
 * @package    DolphinGTK
 * @author     Askarov Ruslan
 * @copyright  Askarov Ruslan (c) 2010.
 * @link       http://groups.google.com/group/dolphingtk
 * @license    http://www.opensource.org/licenses/gpl-license.php GPL
 * @version    0.1
 * @since      PHP v.: 5.2.1
 * @subpackage desktop
 * @category   module
 * @filesource
 */


class Control
{
  private static $lock = false;

  public function set()
  {
    $apache = Widgets::button('Start / Restart', 'images/apache.png', array('Control','restart', 'apache') );
    $mysql  = Widgets::button('Start / Restart', 'images/mysql.png', array('Control','restart', 'mysql') );

    $control = new GtkVBox();
    $hbox    = new GtkHBox();
    $control->pack_start($hbox, 0, 0);
    $hbox->pack_start($apache, 0, 0);
    $hbox->pack_start($mysql, 0, 0);
    return $control;
  }


  public function restart( $bottom, $service )
  {
    if( self::$lock ) return false;
    self::$lock = true;

    if( $service == 'apache' ) {
      Apache::restart();
      Win::statusbar_update( i18n('Apache success restarted ...') );
    } else {
      $proc = OS::exec('ps -e | grep mysqld | awk \'{print $1}\' | tail -1');
      if( is_numeric( $proc ) ) {
        print OS::exec('/etc/init.d/mysql restart');
        Win::statusbar_update( i18n('Mysql success restarted ...') );
      } else {
        print OS::exec('/etc/init.d/mysql start');
        Win::statusbar_update( i18n('Mysql success started ...') );
      }
    }
    self::$lock = false;
  }
}
?>
